package com.yict.csms.baseInfo.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.yict.common.dao.impl.CommonDao;
import com.yict.csms.baseInfo.entity.ContractType;
import com.yict.csms.company.entity.Contract;
import com.yict.csms.system.entity.Wharf;

/**
 * 
 * 
 * @author Patrick.Deng
 * 
 */
@Repository
public class ContractTypeDaoImpl extends CommonDao<ContractType, Long> {

	public boolean verifyContract(Long typeId) {
		boolean bool = false;
		int count = -1;
		String queryString = "select count(*) from Contract as c where c.contractType.typeId = :typeId";
		try {
			Query query = this.getSession().createQuery(queryString);
			query.setLong("typeId", typeId);
			count = ((Number) query.uniqueResult()).intValue();
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (count == 0) {
			bool = true;
		}
		return bool;
	}

	public ContractType findById(Long id) {
		return (ContractType)this.getTemplate().get(ContractType.class, id);
	}
	
	public List<ContractType> getContractTypeSelectMap() {
		List<ContractType> list = new ArrayList<ContractType>();
		String queryString = "from ContractType as c order by c.createDate desc";
		try {
			list = this.getTemplate().find(queryString);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
	public List<Wharf> getWharfSelectMap() {
		List<Wharf> list = new ArrayList<Wharf>();
		String queryString = "from Wharf as c";
		try {
			list = this.getTemplate().find(queryString);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
}
